/**
 * 
 */
package com.banyingli.handler;

import java.util.ArrayList;
import java.util.List;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import com.banyingli.entity.Albulm;
import com.banyingli.entity.PhotoType;
import com.banyingli.entity.Song;
import com.banyingli.entity.Video;
import com.banyingli.entity.VideoType;

/**
 * @ClassName: SingerXMLHandler
 * @Description: TODO 整个应用需要的数据的解析
 * @date 2011-8-10 下午05:15:53
 * 
 */
public class SingerXMLHandler extends DefaultHandler {

	private StringBuffer buffer = new StringBuffer();
	private List<VideoType> list_video_type;
	private List<PhotoType> list_photo_type;
	private List<Albulm> list_albulm;
	private List<Song> list_song;
	private List<Video> list_video;
	private List<String> list_photo;
	private Video video;
	private Song song;
	private VideoType videoType;
	private PhotoType photoType;
	private Albulm albulm;

	@Override
	public void characters(char[] ch, int start, int length)
			throws SAXException {
		// TODO Auto-generated method stub
		buffer.append(ch, start, length);
		super.characters(ch, start, length);
	}

	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {
		// TODO Auto-generated method stub
		if (localName.equals("albulm")) {
			albulm = new Albulm();
		} else if (localName.equals("photo")) {
			photoType = new PhotoType();
		} else if (localName.equals("video_type")) {
			videoType = new VideoType();
		} else if (localName.equals("song")) {
			song = new Song();
		} else if (localName.equals("video")) {
			video = new Video();
		} else {

		}

		super.startElement(uri, localName, qName, attributes);
	}

	@Override
	public void endElement(String uri, String localName, String qName)
			throws SAXException {
		// TODO Auto-generated method stub

		if (localName.equals("albulm")) {
			albulm.setList_song(list_song);
			list_albulm.add(albulm);
		} else if (localName.equals("photo")) {
			// list_photo_type.add(photoType);
		} else if (localName.equals("media")) {
			// list_video_type.add(videoType);
		} else if (localName.equals("albulm_name")) {
			albulm.setAlbulm_name(buffer.toString().trim());
			buffer.setLength(0);
		} else if (localName.equals("publish_date")) {
			albulm.setPublish_date(buffer.toString().trim());
			buffer.setLength(0);
		} else if (localName.equals("albulm_icon")) {
			albulm.setAlbulm_icon(buffer.toString().trim());
			buffer.setLength(0);
		} else if (localName.equals("song")) {
			list_song.add(song);
		} else if (localName.equals("song_name")) {
			song.setSong_name(buffer.toString().trim());
			buffer.setLength(0);
		} else if (localName.equals("words_author")) {
			song.setWords_author(buffer.toString().trim());
			buffer.setLength(0);
		} else if (localName.equals("melody_author")) {
			song.setMelody_author(buffer.toString().trim());
			buffer.setLength(0);
		} else if (localName.equals("song_url")) {
			song.setUrl(buffer.toString().trim());
			buffer.setLength(0);
		} else if (localName.equals("song_lrc")) {
			song.setLrc(buffer.toString().trim());
			buffer.setLength(0);
		} else if (localName.equals("video_type")) {
			list_video_type.add(videoType);
		} else if (localName.equals("video_type_name")) {
			videoType.setVideo_type_name(buffer.toString().trim());
			buffer.setLength(0);
		} else if (localName.equals("video_name")) {
			video.setVideo_name(buffer.toString().trim());
			buffer.setLength(0);
		} else if (localName.equals("video_url")) {
			video.setVideo_url(buffer.toString().trim());
			buffer.setLength(0);
		} else if (localName.equals("video")) {
			list_video.add(video);
		} else if (localName.equals("photo_type")) {
			photoType.setList_image_url(list_photo);
			list_photo_type.add(photoType);
		} else if (localName.equals("photo_type_name")) {
			photoType.setPhoto_type_name(buffer.toString().trim());
			buffer.setLength(0);
		} else if (localName.equals("image_url")) {
			list_photo.add(buffer.toString().trim());
			buffer.setLength(0);
		} else {

		}

		super.endElement(uri, localName, qName);
	}

	@Override
	public void startDocument() throws SAXException {
		// TODO Auto-generated method stub
		list_albulm = new ArrayList<Albulm>();
		list_photo_type = new ArrayList<PhotoType>();
		list_video_type = new ArrayList<VideoType>();
		list_song = new ArrayList<Song>();
		list_video = new ArrayList<Video>();
		list_photo = new ArrayList<String>();
		super.startDocument();
	}

	@Override
	public void endDocument() throws SAXException {
		// TODO Auto-generated method stub
		super.endDocument();
	}

}
